package com.ywy.search.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ywy.controller.BaseController;
import com.ywy.search.model.PostDocument;
import com.ywy.search.service.ESService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 首页Controller
 *
 * @author ywy
 * @date 2021/12/24 13:41
 */
@Controller
public class SearchController extends BaseController {
    @Autowired
    private ESService esService;

    /**
     * 搜索文章
     * @param q
     * @return
     */
    @RequestMapping("/search")
    public String search(String q) {
        IPage<PostDocument> pageData = esService.search(getPage(), q);
        req.setAttribute("pageData", pageData);
        req.setAttribute("q", q);
        return "post/search";
    }
}
